<template>
  <div>
    <el-dialog append-to-body title="编辑分类" class="noselect"
               v-dialogdrag=" { target:'.el-dialog__header',container:'.el-dialog',border:'.el-dialog__wrapper'}"
               :close-on-click-modal="false" :visible.sync="showDialog" :before-close="handleClose">
      <div style="margin: 20px;"></div>
      <template>
        <el-table
          :data="tableData"
          stripe
          border
          style="width: 100%">
          <el-table-column
            prop="date"
            label="分类名称"
            width="180">
            <template scope="scope">
              <span>{{scope.row.name}}</span>
            </template>
          </el-table-column>

          <el-table-column
            prop="address"
            label="操作">
            <template scope="scope">
              <el-button type="text" @click="handleDelete(scope.$index,scope.$index,scope.row.id)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <div class="foot-bar-button">
        <el-button type="primary" @click="submitForm()" size="medium">提交</el-button>
        <el-button @click="resetForm('modelForm')" size="medium">取消</el-button>
      </div>
    </el-dialog>
    <PluginConfirm
      :show="dialogIsShow"
      @chooseSure="chooseSure()"
      @chooseCancel="chooseCancel()"
      @dialogResult="dialogResult">
    </PluginConfirm>
  </div>
</template>
<script>
  //注意路径
  export default {
    props: ['isShow', 'id'],  //参数
    data() {
      return {
        modelForm: {
          attribute:'1'
        },
        showDialog: false,
        activityId: "",
        isSave: true,
        downCategeryId: [],
        isUpdate: false,
        tableData:[],
        dialogIsShow:false,
        curDataRow:null,
        curDataIndex:0,
        selectItmeIndex:"",
        selectItemDetailsIndex:"",
        selectDelId:"",
        chooseTypes:[],
        storeId:window.localStorage.getItem("dishKuId")

      };
    },

    watch: {
      isShow: function (newValue, oldValue) {
        this.showDialog = newValue;
        if (newValue) {
          this.isSave = true;
          this.isUpdate=false;
          this.$axios.get("dishes/dishesFeedCategorys?storeId="+this.storeId).then(data => {
            this.tableData = data.content;
          });
        }

      }
    },
    created() {
      window.this = this;
    },
    methods: {
      goBack() {
        this.router.go(-1);
      },
      submitForm() {
        this.$emit('close');
        this.showDialog = false;
        return;
        var data={};
        if(this.tableData.length<=0) {

          return;
        }
        var k=[];
        for(var i=0;i<this.tableData.length;i++) {
          k.push({id:this.tableData[i].id,chooseType:this.tableData[i].chooseType});
        }
        console.log(k);
        data.details=k;
        this.$axios.put("dishes/dishesFeedCategorys/update",data,"json").then(data => {
          if (data.status == 200) {
            this.$message({
              message: data.message,
              type: 'success'
            });
            this.$emit('addSuccess');
          } else {
            this.$message.error(data.message);
          }
        })


      },
      handleDelete(index,delIndex,id) {
        this.selectItmeIndex=index,
          this.selectItemDetailsIndex=delIndex;
        this.selectDelId=id;
        this.dialogIsShow=true;
      },
      dialogResult(param){
        this.dialogIsShow=param.close;
        if(param.choose==="ok"){
          //console.log("确定");
          this.$axios.delete("dishes/dishesFeedCategorys/"+this.selectDelId).then(data=>{
            if(data.status==200){
              this.tableData.splice(this.curDataIndex,1);
              this.$message({
                type: 'success',
                message: '删除成功!'
              });
              this.initData();
            }else{
              this.$message({
                type: 'error',
                message: data.message
              });
            }
          })
        }else if(param.choose==="cancel"){
          //console.log("取消");
        }else{
          //console.log("不做处理");
        }
      },
      resetForm(formName) {
        this.$emit('close');
        this.showDialog = false;
      },
      handleClose(done) {
        this.$emit('close');
        done();
      },
      isNum(item, key) {
        var r = /^\+?[1-9][0-9]*$/;
        if (!r.test(item[key])) {
          item[key] = "0.00"
        } else {
          item[key] = item[key]
        }
      },
      isDouble(item, key) {
        var isNum = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
        if (!isNum.test(item[key])) {
          item[key] = "0.00"
        } else {
          item[key] = item[key]
        }
      }
    }
  }
</script>
<style scoped>
  .el-from-item_content {
    line-height: 36px;
    position: relative;
    font-size: 15px;
  }
  .el-from-item_title {
    text-align: right;
    vertical-align: middle;
    float: left;
    font-size: 14px;
    color: #48576a;
    line-height: 1;
    padding: 11px 12px 11px 0;
    box-sizing: border-box;
  }
</style>
